package com.sdleyou.treepro.business.api.appointment;

import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.AppointmentManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

/**
 * 成就控制器
 */
@RestController
@RequestMapping("/api")
public class AppointmentController {
    @Autowired
    private AppointmentManager appointmentManager;

    @GetMapping("/{version}/appointments")
    public ResultVO appointmentActive(@RequestParam("base_id") @NotEmpty(message = "base_id 不为空") String baseId) {
        return ResultVOUtil.success(appointmentManager.getAppointmentActive(baseId));
    }

    @PostMapping("/{version}/appointment/make")
    public ResultVO makeOrder(@RequestParam("user_id") @NotEmpty(message = "user_id 不为空") String userId,
                              @RequestParam("active_id") @NotEmpty(message = "active_id 不为空") String activeId,
                              @RequestParam("order_time") @NotEmpty(message = "order_time 不为空") String orderTime,
                              @RequestParam("well_id") @NotEmpty(message = "well_id 不为空") String wellId) {
        appointmentManager.makeAppointment(userId, activeId, orderTime, wellId);
        return ResultVOUtil.success();
    }

    @GetMapping("/{version}/appointment/own")
    public ResultVO myOrder(@RequestParam("user_id") @NotEmpty(message = "user_id 不为空") String userId,
                            @RequestParam(name = "page_size", defaultValue = "5") Integer pageSize,
                            @RequestParam(name = "page_num", defaultValue = "1") Integer pageNum) {
        return ResultVOUtil.success(appointmentManager.myAppointment(userId, pageSize, pageNum));
    }

    @PostMapping("/{version}/appointment/cancel")
    public ResultVO cancelOrder(@RequestParam("user_id") @NotEmpty(message = "user_id 不为空") String userId,
                                @RequestParam("appointment_id") @NotEmpty(message = "appointment_id 不为空") String appointmentId) {
        appointmentManager.cancelAppointment(userId, appointmentId);
        return ResultVOUtil.success();
    }
}
